import menuStore from "@/store/menu";
import { findMenu } from "@/utils";
import { Navigate, useLocation, useNavigate } from "react-router-dom";
import NProgress from "@/config/nprogress";
import { useEffect } from "react";
const AppRoute = ({ children }: any) => {
    NProgress.start();
    const token = localStorage.getItem('token');
    const location = useLocation();
    const { menu } = menuStore();
    const currentMenu = findMenu(menu, location.pathname, true);
    console.log(111);
    useEffect(() => {
        console.log(111);
        NProgress.done();
    }, [location.pathname])

    if (currentMenu) {
        document.title = currentMenu.meta?.title || '后台管理系统'
    }
    return token ? children : <Navigate replace to="/login"></Navigate>
}

export default AppRoute;
